package com.huawei.service.impl;


import com.alibaba.fastjson.JSON;
import com.huawei.dao.DingdanMapper;
import com.huawei.dao.UserMapper;

import com.huawei.entity.Dingdan;
import com.huawei.entity.User;
import com.huawei.service.UserService;
import com.huawei.util.Result;
import com.huawei.util.TokenUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
    @Service
public class UserImpl implements UserService {
    @Resource
    UserMapper userMapper;
        @Resource
        DingdanMapper dingdanMapper;
    @Override
    public List<User> selectAll(Map<String, Object> pars) {

        List<User> list=userMapper.selectAll(pars);
        for(User n:list){
           n.setDingdan1(dingdanMapper.getId(n.getId()));
        }

     return list;
    }

    @Override
    public int count(Map<String, Object> pars) {
        return userMapper.count(pars);
    }

    @Override
    public int add(User user) {

           return userMapper.add(user);

    }

    @Override
    public int update(User user) {

            return userMapper.update(user);

    }

    @Override
    public int delete(int id) {
        return userMapper.delete(id);
    }

        @Override
        public User getId(int id) {
            return userMapper.getId(id);
        }

        @Override
        public String denglu(Integer id,String name, String password) {

            User user = userMapper.denglu(id,name,password);
            if(name!=null){



                String token= TokenUtil.token(id,name,password);
                return token;
            }else {
                return  null;

            }
        }
    }
